package com.co.vote.utils;

import javax.servlet.http.HttpSession;

import com.co.server.entity.user.TUsers;
import com.co.server.service.user.impl.UsersSession;
import com.co.vote.constant.SessionConstant;

public class SessionUtil {

	//获得用户session
	public static UsersSession getUserSession(HttpSession session){
		 UsersSession usersSession = (UsersSession)session.getAttribute(SessionConstant.SESSION_USER);
		 return usersSession;
	}
	//获得用户
	public static TUsers getUser(HttpSession session){
		UsersSession usersSession = getUserSession(session);
		TUsers tUser = usersSession.gettUsers();
		return tUser;
	}
	//获得用户Id
	public static Integer getUserId(HttpSession session){
		TUsers tUser = getUser(session);
		Integer userId = tUser.getUserId();
		return userId;
	}
	
	//将用户保存到session
	public static void setUser(TUsers user,HttpSession session){
		UsersSession userSession = getUserSession(session);
		userSession.settUsers(user);
		session.setAttribute(SessionConstant.SESSION_USER, userSession);
	}
	
}
